//
//  DetailCompereHelp.m
//  JZMCFM
//
//  Created by Mc on 15/10/31.
//  Copyright (c) 2015年 陈卓. All rights reserved.
//

#import "DetailCompereHelp.h"

@implementation DetailCompereHelp
+ (instancetype)sharedInstance
{
    static DetailCompereHelp *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[DetailCompereHelp alloc] init];
    });
    return manager;
}

- (void)downLoadWithUrlString:(NSString *)urlString WithResultBlock:(ResultBlock)resultBlock
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        [SVProgressHUD showWithStatus:@"数据加载" maskType:SVProgressHUDMaskTypeBlack];
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        manager.requestSerializer = [AFJSONRequestSerializer serializer];
        [manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSMutableArray *listArray = responseObject[@"list"];
            [self.detailArray removeAllObjects];
            for (NSDictionary *dict in listArray) {
                
                DetailCompereModel *p = [[DetailCompereModel alloc] init];
                [p setValuesForKeysWithDictionary:dict];
                [self.detailArray addObject:p];
                
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                resultBlock();
            });
            [SVProgressHUD showSuccessWithStatus:@"数据成功" duration:1.0];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"%@",error);
        }];
    });
}


- (NSMutableArray *)detailArray
{
    if (!_detailArray) {
        _detailArray = [NSMutableArray array];
    }
    return _detailArray;
}

@end
